package com.example.controller;

import com.example.pojo.Student;
import com.example.service.IStudentService;
import com.example.util.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 宋伟宁
 * @Date 2023/10/19
 * @Version 1.0
 **/
@RestController
@CrossOrigin
@RequestMapping("/student")
public class StudentController {

    @Resource
    private IStudentService studentService;

    @GetMapping("/stus")
    public R findAll(@RequestParam(name = "offset",defaultValue = "1")Integer offset,
                                    @RequestParam(name="pagesize",defaultValue = "3")Integer pagesize,
                                  @RequestParam(name = "name",required = false)String name){
        return  new R<>(200,true,"查询成功",this.studentService.findAll(offset,pagesize,name));
    }

    @PostMapping("/")
    public  R save(@RequestBody Student student){
         return  this.studentService.save(student)
                 ? new R<>(200,true,"新增成功")
                 : new R<>(201,false,"新增成功");

    }

    @DeleteMapping("/{ids}")
    public  R delete(@PathVariable String ids){
        return  this.studentService.delete(ids)
                ? new R<>(200,true,"删除成功")
                : new R<>(201,false,"删除成功");

    }


}
